import { configureStore } from '@reduxjs/toolkit';
import { persistStore, persistReducer } from 'redux-persist';
import storage from 'redux-persist/lib/storage'; // 默认使用 localStorage
import { combineReducers } from "redux";
import menuReducer from "./menu";
import routeReducer from "./route";

const menuPersistConfig = {
  key: 'menu',
  storage,
  blacklist: []
};
const routePersistConfig = {
  key: 'route',
  storage,
  whitelist: ['routerUrl']
};
// 使用 persistReducer 包装 menuReducer 和 routeReducer
const persistedMenuReducer = persistReducer(menuPersistConfig, menuReducer);
const persistedRouteReducer = persistReducer(routePersistConfig, routeReducer);
// 组合 reducer
const rootReducer = combineReducers({
  menu: persistedMenuReducer,
  route: persistedRouteReducer,
});
const store = configureStore({
  reducer: rootReducer,
  middleware: (getDefaultMiddleware) =>
    getDefaultMiddleware({
      serializableCheck: false, // 禁用严格模式
    }),
});

const persistor = persistStore(store);    

export { store, persistor };